<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let Counter = function () {
                let privateCounter = 0;
                function changeBy(val) {
                    privateCounter += val;
                }
                return {
                    increment: function () {
                        changeBy(1);
                    },
                    decrement: function () {
                        changeBy(-1);
                    },
                    value: function () {
                        return privateCounter;
                    },
                };
            };
            let Counter1 = Counter();
            let Counter2 = Counter();
            Counter1.increment();
            console.log(Counter1.value());
            console.log(Counter2.value());
        </script>
    </body>
</html>
